package com.hyq.market.ui.home.gclass;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.hannesdorfmann.mosby.mvp.MvpPresenter;
import com.hyq.market.R;
import com.hyq.market.adapter.GoodsClassAdapter;
import com.hyq.market.adapter.SubClassAdapter;
import com.hyq.market.api.Constant;
import com.hyq.market.base.AbsFragment;
import com.hyq.market.bean.GClass;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by Administrator on 2017/7/19 0019.
 */

public class ClassFt extends AbsFragment implements IViewClass {
    View rootView;
    @BindView(R.id.radio_group)
    RecyclerView radioGroup;
    @BindView(R.id.recycler_sub_class)
    RecyclerView recyclerSubClass;
    @BindView(R.id.text_menu_title)
    TextView textMenuTitle;
    @BindView(R.id.img)
    ImageView img;
    private Unbinder unbinder;
    private GoodsClassAdapter goodsClassAdapter;
    PersenterClass presenter;
    private SubClassAdapter subClassAdapter;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_layout_class, null);
        unbinder = ButterKnife.bind(this, rootView);
        presenter = new PersenterClass(this);
        initView();
        return rootView;
    }

    void initView() {
        goodsClassAdapter = new GoodsClassAdapter();
        goodsClassAdapter.setOnItemClickListener(presenter);
        goodsClassAdapter.setOnItemChildClickListener(presenter);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
        radioGroup.setLayoutManager(linearLayoutManager);
        radioGroup.setAdapter(goodsClassAdapter);
        radioGroup.setNestedScrollingEnabled(false);
//
//
        subClassAdapter = new SubClassAdapter();
        subClassAdapter.setOnItemChildClickListener(presenter);
        subClassAdapter.setOnItemClickListener(presenter);
        GridLayoutManager gridLayoutManager2 = new GridLayoutManager(getContext(), 3);
        recyclerSubClass.setLayoutManager(gridLayoutManager2);
        recyclerSubClass.setAdapter(subClassAdapter);
        recyclerSubClass.setNestedScrollingEnabled(false);
    }


    @Override
    protected void lazyLoad() {

    }

    @Override
    public MvpPresenter createPresenter() {
        //  presenter = new PersenterClass(this);
        return presenter;
    }

    @Override
    public void onStart() {
        super.onStart();
        presenter.getData(null);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public <T> void loadData(T t) {

    }


    @Override
    public BaseQuickAdapter getAdapter(int tyepe) {
        switch (tyepe) {
            case 1:
                return goodsClassAdapter;
            case 2:

                return subClassAdapter;
            default:
                return goodsClassAdapter;
        }
    }


    @Override
    public void setSubTitle(GClass.DataBean.CateListBean cateListBean) {
        textMenuTitle.setText(cateListBean.getName());
        Glide.with(getContext()).load(Constant.BASE_Url + cateListBean.getAdvimg())
                .error(R.mipmap.class_error)
                .into(img);
    }
}
